package com.example.mvc.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class MyAop {

//    @Pointcut(value = "execution(* com.example.mvc.controller.MyController.aa(..)) && args(path)", argNames = "path")
//    public void point(String path){}


    @AfterReturning(value = "execution(* com.example.mvc.controller.MyController.aa(..))", returning = "str")
    public void aaAop(JoinPoint joinPoint, String str) {

        Object[] args = joinPoint.getArgs();

        if (args != null && args.length > 0) {
            for (int i = 0; i < args.length; i++) {
                log.info("arg --- {} --- {}", i, args[i]);
            }
        }
        if (str.equals("error")) {
            return;
        }
        log.info("return : {}", str);

//        log.info("joinPoint : {}", joinPoint);

    }


}
